﻿using AntdUI;
using Super.Admin.ViewModels.Base;

namespace Super.Admin.Models.Role
{
    public class RoleBaseModel : ViewModelBase
    {
        private bool _check;
        /// <summary>
        /// 是否选中
        /// </summary>
        public bool Check
        {
            get { return _check; }
            set
            {
                if (_check == value) return;
                SetProperty<bool>(ref _check, value);
            }
        }
        /// <summary>
        /// 角色基础模型
        /// </summary>
        public int Index { get; set; }
        /// <summary>
        /// 创建时间和更新时间
        /// </summary>
        public string CreateTime { get; set; }
        /// <summary>
        /// 更新时间
        /// </summary>
        public string UpdateTime { get; set; }
        /// <summary>
        /// 角色ID
        /// </summary>
        public int Id { get; set; } = -1;
        private string _name;
        /// <summary>
        /// 角色名称
        /// </summary>
        public string Name
        {
            get { return _name; }
            set
            {
                SetProperty(ref _name, value);
                ValidateContent();
            }
        }
        private int _isActive;
        /// <summary>
        /// 是否启用
        /// </summary>
        public int IsActive
        {
            get { return _isActive; }
            set { SetProperty(ref _isActive, value); }
        }
        private string _remark;
        /// <summary>
        /// 备注信息
        /// </summary>
        public string Remark
        {
            get { return _remark; }
            set { SetProperty(ref _remark, value); }
        }

        public CellLink[] Operates { get; set; }
        public CellTag[] IsActiveTag { get; set; }

        /// <summary>
        /// 验证内容的有效性
        /// </summary>
        public override void ValidateContent()
        {
            if (string.IsNullOrEmpty(Name))
            {
                AddError("权限名称不能为空", nameof(Name));
            }
            else
                ClearErrors(nameof(Name));
            base.ValidateContent();
        }
    }
}
